package com.hmall.trade.listener;

import com.hmall.trade.service.IOrderService;
import lombok.RequiredArgsConstructor;
import org.apache.rocketmq.spring.annotation.ConsumeMode;
import org.springframework.stereotype.Component;
import org.springframework.stereotype.Service;
import lombok.extern.slf4j.Slf4j;
import org.apache.rocketmq.spring.annotation.MessageModel;
import org.apache.rocketmq.spring.annotation.RocketMQMessageListener;
import org.apache.rocketmq.spring.core.RocketMQListener;


//消息消费服务
@Slf4j
@Service
@RequiredArgsConstructor
public class ConsumeService {
    private final IOrderService orderService;
    @Component
    //topic需要和生产者的topic一致；consumerGroup属性必须指定，内容可随意；messageModel默认为CLUSTERING
    @RocketMQMessageListener(nameServer = "${rocketmq.name-server}", topic = "msg-topic", consumerGroup = "${rocketmq.consumer.group0}", messageModel = MessageModel.BROADCASTING)
    class ConsumerInGroup0 implements RocketMQListener<Long> {
        @Override
        public void onMessage(Long id) {
            //消息体（Payload）o为JSON对象(字符串)
            log.info("C0开始消费消息:{}", id);
            orderService.markOrderPaySuccess(id);
        }
    }

}